package com.hnzbxy.api.biz.converter;

import com.hnzbxy.api.biz.entity.Teacher;
import com.hnzbxy.api.biz.vo.TeacherVO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 教员VO与实体类转换器
 * @Author xiaoge
 * @Date 2020/3/10 11:53
 * @Version 1.0
 **/
public class TeacherConverter {

    /**
     * VO转实体类
     */
    public static Teacher converterToEntity(TeacherVO vo) {
        Teacher entity = new Teacher();
        BeanUtils.copyProperties(vo, entity);
        // 性别VO是String，实体是Integer，需转换
        if (vo.getGender() != null) {
            entity.setGender(Integer.parseInt(vo.getGender()));
        }
        return entity;
    }

    /**
     * 实体类转VO
     */
    public static TeacherVO converterToVO(Teacher entity) {
        TeacherVO vo = new TeacherVO();
        BeanUtils.copyProperties(entity, vo);
        // 性别实体是Integer，VO是String，需转换
        if (entity.getGender() != null) {
            vo.setGender(entity.getGender().toString());
        }
        return vo;
    }

    /**
     * 实体类列表转VO列表
     */
    public static List<TeacherVO> converterToListVO(List<Teacher> entityList) {
        List<TeacherVO> voList = new ArrayList<>();
        for (Teacher entity : entityList) {
            voList.add(converterToVO(entity));
        }
        return voList;
    }

}